package com.cloudptt.api.product.func.call.group;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.api.models.call.RtcpMsg;
import com.cloudptt.api.pjsip.api.SipCallSession;
import com.cloudptt.api.pjsip.service.AppRTCAudioManager;
import com.cloudptt.api.product.func.IFunc;
import com.cloudptt.api.product.func.addr.IAddrOp;
import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.CallListener;
import com.cloudptt.api.product.func.call.ICallHistory;
import com.cloudptt.api.product.func.call.ICallMute;
import com.cloudptt.api.product.func.call.group.fsm.call.GroupCallAgent;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.CallOperator;
import com.cloudptt.api.product.parser.ErrParser;
import com.cloudptt.api.product.res.Resource;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.config.model.ServerInfo;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.UserInfo;

import android.content.Context;

import org.pjsip.pjsua2.pjsip_inv_state;
import org.pjsip.pjsua2.pjsua_call_media_status;



public class GroupCallTracker implements IFunc,ICallMute//,ICallState,ISubState
{
	public final static String THIS_FILE = "GroupCallTracker";
	private final static int MAX_GROUP_CALL_NUM = 2;

	private Context ctx = null;
	private McIdInfo mcIdInfo = null;
	private CallOperator operator = null;
	private ICallMute callMute = null;
	private IAddrOp addrOp = null;
	private ICallHistory callHistory = null;

	private GroupCallBroadcast broadcast = null;

	private CallListener callListener = null;
	private GroupCallSpeakListener floorListener = null;
	private GroupCallAgent curCallAgent = null;
	private Object callMutex = new Object();

	private Map<String,GroupCallAgent> callMap = new HashMap<String,GroupCallAgent>();

	public GroupCallTracker(Context ctx,McIdInfo mcIdInfo,IAddrOp addOp,CallOperator operator,ICallMute callMute)
	{
		this.ctx = ctx;
		this.mcIdInfo = mcIdInfo;
		this.addrOp = addOp;
		this.operator = operator;
		this.callMute = callMute;
		this.broadcast = new GroupCallBroadcast(ctx,this);
	}

	public int newCall(CallAttr callAttr)
	{
		if(callMap.size() >= MAX_GROUP_CALL_NUM)
		{
			return CauseCont.OperateCheck_Call_CallTooMany;
		}
		boolean isNull =  curCallAgent == null;
		Log.d(THIS_FILE, "newCall  moCallAgent = " + isNull);
		Log.d(THIS_FILE, "newCall  callAttr = " + callAttr);

		GroupCallAgent agent = new GroupCallAgent(ctx,callAttr,mcIdInfo,operator,addrOp);
		agent.setListener(callListener,floorListener);
		String callKey = callAttr.getCallKey();
		callMap.put(callKey, agent);

		return CauseCont.OperateCheck_Suc;
	}


	public boolean isHasCall(String callKey)
	{
		Log.d(THIS_FILE, "isHasCall callKey = " + callKey);
		if(callKey != null
				&& this.getCallAgent(callKey) != null)
		{
			return true;
		}
		return false;
	}
	public int doUserAction(String callKey,int userAction)
	{
		Log.d(THIS_FILE, "doUserAction userAction = " + CallConst.userActionTag(userAction));
		if(CallConst.BtnAction_Vol_Up == userAction)
		{
			int result = onVol(AppRTCAudioManager.Vol_Type_Up);
			return result;
		}
		else if(CallConst.BtnAction_Vol_Down == userAction)
		{
			int result = onVol(AppRTCAudioManager.Vol_Type_Down);
			return result;
		}
		GroupCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			this.curCallAgent = callAgent;
			int result = callAgent.doUserAction(userAction);
			Log.d(THIS_FILE, "doUserAction result = " + result);
			return result;
		}
		return -1;
	}
	//@Override
	public void receiveCallAction(String callKey,int talkAction) {
		// TODO Auto-generated method stub
		Log.d(THIS_FILE, "receiveCallAction callKey = " + callKey + " talkAction = " + talkAction);
		GroupCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			callAgent.receiveCallAction(talkAction);
			if(CallConst.Session_Disconnected == talkAction)
			{
				clearCall(callKey);
			}
		}

		//		if(curCallAgent != null)
		//		{
		//			curCallAgent.receiveCallAction(talkAction);
		//			if(CallConst.Session_Disconnected == talkAction)
		//			{
		//				clearCall(callKey);
		//			}
		//		}

	}

	public int onVol(int type)
	{
		//		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		operator.onVol(type);
		return CauseCont.OperateCheck_Suc;
	}
	//@Override
	public void receiveRtcpMsg(String callIdStr,RtcpMsg msg) {
		// TODO Auto-generated method stub
		Log.d(THIS_FILE, "receiveRtcpMsg callIdStr = " + callIdStr + " msg = " + msg);
		GroupCallAgent callAgent = this.getCallAgentByCallIdStr(callIdStr);
		if(callAgent != null)
		{
//			operator.setSpeakerphoneOn(true);
			callAgent.receiveRtcpMsg(msg);
		}
		else
		{
			Log.d(THIS_FILE, "receiveRtcpMsg callAgent = null");
		}
		//		if(curCallAgent != null)
		//		{
		//			curCallAgent.recei veRtcpMsg(msg);
		//		}
	}

	public void incomingCall(SipCallSession callSession)
	{
		if(callSession == null)
		{
			return;
		}


		String imcomingNum = callSession.getRemoteContact();
		Log.d(THIS_FILE, "incomingCall imcomingNum = " + imcomingNum);

		int callType = callSession.getCallType();

		AddrInfo imcomingInfo = null;
		boolean isGroup = false;
		if(callType == CallAttr.CallType_Group)
		{
			imcomingInfo = addrOp.getGroupInfoByNum(imcomingNum);
			isGroup = true;
		}
		else if(callType == CallAttr.CallType_Single_half)
		{
			imcomingInfo = addrOp.getUserInfoByNum(imcomingNum);
			isGroup = false;
		} 
		else
		{
			return;
		}
		Log.d(THIS_FILE, "incomingCall imcomingInfo = " + imcomingInfo);
		if(imcomingInfo == null)
		{
			return;
		}
		//String callingUserNum = callSession.getCallingUser();
		UserInfo callingUser = mcIdInfo.toUserInfo();//addrOp.getUserInfoByNum(callingUserNum);

		GroupCallAgent oldCallAgent = this.getCallAgent(imcomingNum);
		if(oldCallAgent != null)
		{
			this.clearCall(imcomingNum);
		}

		String callIdStr = callSession.getCallIdStr();
		if(callMap.size() > 0)
		{
			Log.d(THIS_FILE, "incomingCall callMap.size() > 0");
			operator.hangupCall(callIdStr,486);
			return;
		}

		CallAttr callAttr = new CallAttr(imcomingInfo,callingUser,CallAttr.CallDir_MT,isGroup);
		int result = newCall(callAttr);
		Log.d(THIS_FILE, "incomingCall result = " + result);


		GroupCallAgent callAgent = this.getCallAgent(imcomingNum);
		if(callAgent == null)
		{
			Log.d(THIS_FILE, "incomingCall callAgent == null");
			operator.hangupCall(callIdStr,486);
			return;
		}
		this.curCallAgent = callAgent;

		callAgent.updateCallIdStr(callIdStr);
		int callState = callAgent.getState();
		Log.d(THIS_FILE, "incomingCall callIdStr = " + callIdStr + " callState = " + callState);
		if(CallConst.CallState_InitState == callState
				&& result == CauseCont.OperateCheck_Suc)
		{
//			addrOp.setCurGroupInfo(imcomingInfo);
			if(callType == CallAttr.CallType_Group
					|| callType == CallAttr.CallType_Single_half)
			{
				callMute.muteCall(true);
				callAgent.doAcceptAction();
			}
		}
		else
		{
			result = operator.hangupCall(callIdStr,486);
			if(result != CauseCont.OperateCheck_Suc) 
			{
				String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
				CommDlg.showToast(ctx,errStr);
				return;
			}
		}
	}

	public void recvCallSession(SipCallSession callSession)
	{
		Log.d(THIS_FILE, "recvCallSession into ");
		synchronized (callMutex) 
		{

			if(callSession == null)
			{
				return;
			}
			int callType = callSession.getCallType();
			if(callType != CallAttr.CallType_Group
					&& callType != CallAttr.CallType_Single_half)
			{
				return;
			}

			Log.d(THIS_FILE, "recvCallSession callSession " + callSession.toString());
			String imcomingNum = callSession.getRemoteContact();
			Log.d(THIS_FILE, "recvCallSession imcomingNum = " + imcomingNum);
			int callId = callSession.getCallId();
			GroupCallAgent callAgent = this.getCallAgent(imcomingNum);
			int state = callSession.getCallState();
			Log.d(THIS_FILE, "recvCallSession state = " + state);
			if(callAgent == null)
			{
				Log.d(THIS_FILE, "recvCallSession callAgent == null");
				if(pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED != state)
				{
					//					operator.hangupCall(callId,486);
				}
				return;
			}

			//			Log.d(THIS_FILE, "recvCallSession callSession is " + callSession.toString());
			//			int incommingCallstate = callSession.getCallState();
			//			//CONNECTING閻樿埖锟戒焦妲告稉杞扮啊闂冨弶顒涚粭顑跨濞嗏�茬瑐閹躲儲妞傚▽鈩冩箒CALLING閻樿埖锟斤拷
			//			Log.d(THIS_FILE, "recvCallSession curCallSession is " + curCallSession);
			//			if(isReplaceCall()
			//					&& isNewCall(incommingCallstate))
			//			{
			//				curCallSession = callSession;
			//				if(curCallAgent != null)
			//				{
			//					int callId = callSession.getCallId();
			//					this.curCallAgent.updateCallId(callId);
			//				}
			//			}

			//			if(curCallSession != null
			//					&& callSession.getCallId() == curCallSession.getCallId())
			//			{
			//				curCallSession = callSession;
			//				int callId = callSession.getCallId();
			//				if(curCallAgent != null)
			//				{
			//					this.curCallAgent.updateCallId(callId);
			//				}
			//				updateCallTime(callSession);
			String callIdStr = callSession.getCallIdStr();
			callAgent.updateCallIdStr(callIdStr);
			String callKey = callAgent.getCallkey();


			if(pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED == state)
			{

				curCallAgent.negotiateRtpRtcpChannel();
				int lastCode = callSession.getLastStatusCode();
				Log.d(THIS_FILE, "onReceive lastCode is " + lastCode +" remote  "+callSession.getRemoteContact());
				if(SipCallSession.StatusCode.OK == lastCode)
				{
					int mediaState = callSession.getMediaStatus();
					Log.d(THIS_FILE, "onReceive mediaState is " + mediaState);
//					if(pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE == mediaState)
					{
						receiveCallAction(callKey,CallConst.Session_Confirmed_Active);

						//						int mcType = callSession.getMcType();
						boolean isGranted = callSession.isGranted();
						curCallAgent.initServiveAgentByMcType(isGranted);
					}
				}
				else
				{
					int callDir = callAgent.getCallAttr().getCallDir();
					int code = callSession.getLastStatusCode();
					showErrToast(callDir,code,ErrParser.Type_FloorResp);
				}
			}
			else if(pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED == state)
			{
				CallAttr callAttr = callAgent.getCallAttr();
				Log.d(THIS_FILE, "onReceive DISCONNECTED callAttr = " + callAttr);
				//				AddrInfo receiver = callAttr.getGroupInfo();
				AddrInfo sender = callAttr.getCallLogAddrInfo(mcIdInfo);
				Log.d(THIS_FILE, "onReceive DISCONNECTED sender = " + sender);
				int callDir = callAttr.getCallDir();
				int code = callSession.getLastStatusCode();
				//				String secStr = callAgent.getTimeDesc();

				receiveCallAction(callKey,CallConst.Session_Disconnected);
				showErrToast(callDir,code,ErrParser.Type_CallResp);

				addrOp.setCurGroupInfo(null);
				//				newCallHistory(receiver,sender,callDir,code,secStr);
			}
			//			}
			//			else if(InvState.DISCONNECTED == incommingCallstate)
			//			{
			//				int talkState = curCallAgent.getState();
			//				Log.d(THIS_FILE, "onReceive talkState is " + talkState);
			//				receiveCallAction(CallConst.Session_Disconnected);
			//				showErrToast(callSession,ErrParser.Type_CallResp);
			//			}
		}
	}

	//	private void newCallHistory(AddrInfo receiver,AddrInfo sender,int callDir,int code,String secStr)
	//	{
	//		boolean isAdd = false;
	//		StringBuffer contentStr = new StringBuffer();
	//		if(secStr != null)
	//		{
	//			String str = Resource.getString("e_log_suc");
	//			contentStr.append(str).append(secStr);
	//		}
	//		else
	//		{
	//			if(code == 403
	//					|| code == 408
	//					|| code == 486
	//					|| code == 487
	//					|| code == 603)
	//			{
	//				ErrInfo errInfo = new ErrInfo(CauseCont.ERROR_TITLE_LOG, code);
	//				if( errInfo != null )
	//				{
	//					String str = errInfo.getErrDesc();
	//					contentStr.append(str);
	//				}
	//			}
	//			else
	//			{
	//				String str = Resource.getString("e_log_err");
	//				contentStr.append(str + code);
	//			}
	//			
	//			if(code == 408
	//					|| code == 487)
	//			{
	//				isAdd = true;
	//			}
	//		}
	//		int dir = SessionInfo.Direction_Type_Send;
	//		if(callDir == CallAttr.CallDir_MT)
	//		{
	//			dir = SessionInfo.Direction_Type_Receive;
	//		}
	//		if(callHistory != null)
	//		{
	//			callHistory.newCallHistory(receiver, sender,dir,isAdd,contentStr.toString());	
	//		}
	//	}

	public void clearCall(String callKey)
	{
		Log.d(THIS_FILE, "clearCall callKey = " + callKey);
		if(callKey != null
				&& callMap != null)
		{
			GroupCallAgent callAgent = callMap.remove(callKey);
			if(callAgent != null)
			{
				callAgent.destory();
				callAgent = null;
			}
		}
		if(addrOp != null)
		{
			//addrOp.setCurGroupInfo(null);//濮濓絽鐖堕幆鍛枌闂囷拷鐟曚椒绻氶悾锟�
		}
	}

	private GroupCallAgent getCallAgentByCallIdStr(String callIdStr)
	{
		Log.d(THIS_FILE, "getCallAgentByCallIdStr  callIdStr = " + callIdStr);
		if(callMap == null
				|| callMap.size() <=0)
		{
			return null;
		}
		Log.d(THIS_FILE, "getCallAgentByCallIdStr  callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		Log.d(THIS_FILE, "getCallAgentByCallIdStr  keySet = " + keySet);
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			Log.d(THIS_FILE, "getCallAgentByCallIdStr  key = " + key);
			GroupCallAgent callAgent = callMap.get(key);
			if(callAgent != null) {
				String oldCallIdStr = callAgent.getCurCallIdStr();
				Log.d(THIS_FILE, "getCallAgentByCallIdStr  callIdStr = " + callIdStr + " oldCallIdStr = " + oldCallIdStr);
				if (oldCallIdStr != null
					&& oldCallIdStr.equals(callIdStr)) {
					return callAgent;
				}
			}
		}
		return null;
	}

	private GroupCallAgent getCallAgent(String key)
	{
		Log.d(THIS_FILE, "getCallAgent  key = " + key);
		Log.d(THIS_FILE, "getCallAgent  callMap = " + callMap);
		if(callMap == null
				|| callMap.size() <=0)
		{
			return null;
		}
		return callMap.get(key);
	}

	private void showErrToast(int callDir,int code,int type)
	{
		ErrParser errParser = new ErrParser(code, type, ctx);
		if(errParser.isErr()
				&& code != 486
				&& callDir != CallAttr.CallDir_MT)
		{
			String errStr = errParser.getErrStr();
			if(errStr != null
					&& !errStr.equals(""))
			{
				CommDlg.showToast(ctx, errStr);
			}
		}
	}

	//	private void showErrToast(SipCallSession callSession,int type)
	//	{
	//		ErrParser errParser = new ErrParser(callSession, type, ctx);
	//		if(errParser.isErr())
	//		{
	//			String errStr = errParser.getErrStr();
	//			if(errStr != null
	//					&& !errStr.equals(""))
	//			{
	//				CommDlg.showToast(ctx, errStr);
	//			}
	//		}
	//	}

	public boolean isNewCall(int state)
	{
		if(state == pjsip_inv_state.PJSIP_INV_STATE_CALLING
				|| state == pjsip_inv_state.PJSIP_INV_STATE_INCOMING
				|| state == pjsip_inv_state.PJSIP_INV_STATE_CONNECTING)
		{
			return true;
		}
		return false;
	}

	/*瑜版挸澧犻惃鍕嚑閸欘偄鍑＄紒蹇曠波閺夌喍绨￠敍灞藉讲娴犮儴顫﹂弴瀛樻煀閹猴拷*/
	public boolean isReplaceCall(SipCallSession callSession)
	{
		if(callSession == null
				|| callSession.getCallState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED)
		{
			return true;
		}
		return false;
	}

	public void setListener(CallListener callListener,GroupCallSpeakListener speakListener)
	{
		Log.d(THIS_FILE, "setListener");
		this.callListener = callListener;
		this.floorListener = speakListener;
		//		this.videoListener = videoListener;
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			agent.setListener(callListener,speakListener);
		}
	}

	public void setDefaultGroupInfo(AddrInfo info)
	{
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			agent.setDefaultGroupInfo(info);
		}
	}

	public HalfCallInfo getCallInfo(String callKey)
	{
		Log.d(THIS_FILE, "getCallInfo callKey = " + callKey);
		GroupCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			return callAgent.getCallInfo();
		}
		return null;
	}

	public String getCallDesc()
	{
		int size = callMap.size();
		Log.d(THIS_FILE, "getCallDesc size = " + size);
		return "" + size;
	}
	public String getSysInfoStr()
	{
		StringBuffer strBuf = new StringBuffer("GroupCallTracker:");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			strBuf.append(agent.getSysInfoStr());
		}
		return strBuf.toString();
	}

	public List<HalfCallInfo> getTalkInfoList()
	{
		List<HalfCallInfo> list = new Vector<HalfCallInfo>();
		return list;
	}

	public void destory() {
		Log.d(THIS_FILE, "destory");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			agent.destory();
		}
		//		callAttr = null;
	}

	//	@Override
	public boolean isActiveCall(String callKey) {
		// TODO Auto-generated method stub
		GroupCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			return callAgent.isActiveCall();
		}
		return false;
	}

	//	@Override
	public int getState() {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public void onLanChange(String lanType) {
		// TODO Auto-generated method stub

	}
	@Override
	public void onLogined(McIdInfo mcIdInfo,ServerInfo info,boolean isLoginSuc)
	{}
	@Override
	public void doNetworkChange(boolean isConn)
	{
		Log.d(GroupCallAgent.Log_Key, "doNetworkChange isConn = " + isConn);
		if(!isConn)
		{
			destoryAllCall();
		}
	}
	@Override
	public void doForceDetach()
	{
		Log.d(GroupCallAgent.Log_Key, "doForceDetach");
		clearAllCallAgent();
	}
	@Override
	public void doLogout()
	{
		Log.d(GroupCallAgent.Log_Key, "doLogout");
		clearAllCallAgent();
	}
	@Override
	public void doExit()
	{
		Log.d(GroupCallAgent.Log_Key, "CallAgent exit");
		clearAllCallAgent();
		this.broadcast.clearResource();
		broadcast = null;
	}

	//	public CallOperator getOperator() {
	//		return operator;
	//	}

	//	public CallAgent getCallAgent() {
	//		return curCallAgent;
	//	}

	public String toString() 
	{
		StringBuffer strBuff = new StringBuffer("McpttCall:");
		//		strBuff.append("callAttr = ").append(callAttr).append(",");
		//		strBuff.append("callAgent = ").append(callAgent).append(";");

		return strBuff.toString();
	}

	@Override
	public void onKeepAlive(boolean isconnected) {
		// TODO Auto-generated method stub
		if(!isconnected)
		{
			//clearAllCallAgent();
		}
	}

	private void clearAllCallAgent()
	{
		Log.d(THIS_FILE, "clearAllCallAgent callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.remove(key);
			agent.destory();
			agent = null;
		}
	}

	private void destoryAllCall()
	{
		Log.d(THIS_FILE, "clearAllCallAgent callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.remove(key);
			agent.destoryCall();
			agent.destory();
			agent = null;
		}
	}
	public void startSoundPlayer(int type)
	{
		operator.startSoundPlayer(type);
	}

	//	public void setNoSnd()
	//	{
	//		Log.d(THIS_FILE, "setNoSnd");
	//		try {
	//			operator.setNoSnd();
	//		} catch (Exception e) {
	//			// TODO Auto-generated catch block
	//			e.printStackTrace();
	//		}
	//	}
	//	
	//	public void setSnd(boolean isMust)
	//	{
	//		Log.d(THIS_FILE, "setSnd isMust = " + isMust);
	//		try {
	//			operator.setSnd(isMust);
	//		} catch (Exception e) {
	//			// TODO Auto-generated catch block
	//			e.printStackTrace();
	//		}
	//	}
	public void setCallHistory(ICallHistory callHistory) {
		this.callHistory = callHistory;
	}

	@Override
	public void muteCall(boolean isOn) {
		// TODO Auto-generated method stub
		Log.d(THIS_FILE, "muteOnCall callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			agent.muteCall(isOn);
		}
	}


	public void negotiateRtcpChannel() {
		// TODO Auto-generated method stub
		Log.d(THIS_FILE, "muteOnCall callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			GroupCallAgent agent = callMap.get(key);
			agent.negotiateRtcpChannel();
		}
	}
}
